// *** ADDED BY HEADER FIXUP ***
#include <ctime>
// *** END ***
/*
**Author erow
**
*/
#include <iostream>
#include <sys/time.h>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#include "transitHub.h"
#include "Serial.h"

#include "robotModel.h"
#include "gaitStep.h"
/** \brief  test gyp datas
 *
 * \param 1
 * \param 2
 * \return
 *
 */

transitHub* port;


void *thread_function(void *arg)
{
    port->LoopRx();
    pthread_exit(0);
}
int main(int arg,char** args)
{

    //port:1,baud_rate:57600
    // cin>>port>>way;
    logger::m_level=WARN;
    port=transitHub::getInstance();

    int data[20]= {0};
    while(!port->portOpen(1,57600))
    {
        cout<<"fail!\n";
        cout<<"(port way)//ttyS$port"<<endl;
        return 1;
    }
    float s=0;
    string help="\
this progrom for gyp data\n\
cmd:\n\
start :LoopRx for recieve gyp data\n\
end :exit\n\
";
    string cmd;
    cout<<help;

    pthread_t a_thread;
    while(1)
    {
        //cin>>cmd;

        pthread_create(&a_thread,NULL,thread_function, (void *)0);

        while(1)
        {
            if(!port->state.GYP)
                continue;
            double  k=0.1;
            int t;
            cout<<"rx:"<<port->p_acc[0]<<endl;
            t=port->p_acc[0]*k;
            if(t>-200&t<200)
            {
                port->store_data[18]=t;
                port->Tx();
            }
        }

    }


    return 0;
}
